package com.dozen.share;

import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.StrictMode;

import androidx.multidex.MultiDex;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.Utils;
import com.dozen.commonbase.APPBase;
import com.dozen.commonbase.utils.AppInfoUtils;

import org.litepal.LitePal;
import org.litepal.LitePalApplication;

/**
 * @author: Dozen
 * @date: 2020/3/1
 * @description: 基类   click_vip_popup_close
 */
public class MyApplication extends LitePalApplication {

    private static MyApplication application;

    public static MyApplication getApplication() {
        return application;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        APPBase.init(this);
        //初始化数据库
        LitePal.initialize(this);
        //初始化工具
        Utils.init(this);

        //初始化Multidex库
        MultiDex.install(this);

        //取消严格模式  FileProvide 以防在依赖库库调用拍照出现闪退
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }

        if (AppInfoUtils.isAppDebug(this)) {
            ARouter.openDebug();
            ARouter.openLog();
        }
        ARouter.init(this);

        //初始化环境
        initEnvironment();

    }

    //初始化环境
    private void initEnvironment() {

    }

    //字体设置
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }

}
